<?php

namespace Home\Model\Ajax;

class UserEditpwd extends AbstractAjax
{
    // 修改密码
    public function handle()
    {
        $old_password = I('request.old_password', '', 'trim');
        $password     = I('request.password', '', 'trim');
        $username     = session('ytata.username');
        if (empty($this->uid)) {
            $ajax['status'] = 0;
            $ajax['content'] = "请登录后操作！";
            return $ajax;
        }
        if (empty($old_password) || empty($password)) {
            $ajax['status']  = 0;
            $ajax['content'] = "修改失败，数据错误！";
            return $ajax;
        }
        if (D('User')->verify_username_password($username, $old_password)) {
            D('User')->edit_pwd($this->uid, $password);
            $ajax['status']  = 1;
            $ajax['content'] = "密码修改成功！";
            return $ajax;
        } else {
            $ajax['status']  = 0;
            $ajax['content'] = "修改失败，旧密码错误！";
            return $ajax;
        }
    }
}